package com.vodone.v1pin.navigator.delegate
{
	
	import com.vodone.v1pin.core.model.ConditionVO;
	import com.vodone.v1pin.core.model.MainModelLocator;
	import com.vodone.v1pin.navigator.view.vo.NavVO;
	
	import flash.utils.Dictionary;
	
	public class NavigatorConvertUtil
	{
		public static function getNavList( obj:Object , navType:String ):Array
		{
			var list:Array = [];
			var level:int = 0;
			if( navType == NavigatorDelegate.MAIN ){
				MainModelLocator.getInstance().navDict = new Dictionary();
				MainModelLocator.getInstance().navSubappDict = new Dictionary();
			}
			if( obj.hasOwnProperty("data") )
			{
				var tempList:Array = obj["data"];
				var len:int = tempList.length;
				for( var i:int = 0 ; i < len ; i++ ){
					list.push( getNav( tempList[i]  , level , i , navType ) );
				}
			}
			
			return list;
		}
		
		public static function parasId( app:String,id:String,level:int ):String
		{
			return ConditionVO.parasModule(app) + "#" + id
		}
		
		public static function getNav( obj:Object , level:int , index:int , navType:String ):NavVO
		{
			var vo:NavVO = new NavVO();
			vo.index = index;
			vo.level = level;
			if( obj.hasOwnProperty("subapp") )
			{
				vo.subapp = obj["subapp"];
				if( vo.subapp == "categorylist" ){
					vo.subapp = "productList";
				}
			}
			if( obj.hasOwnProperty("name") )
			{
				vo.name = obj["name"];
			}
			if( obj.hasOwnProperty("id1") && obj["id1"] != null && obj["id1"] != "" )
			{
				vo.id1 = parasId(vo.subapp,obj["id1"],level);
				vo.currentId = vo.id1;
			}
			if( obj.hasOwnProperty("id2") && obj["id2"] != null && obj["id2"] != "" )
			{
				vo.id2 = parasId(vo.subapp,obj["id2"],level);
				vo.currentId = vo.id2;
			}
			if( obj.hasOwnProperty("id3") && obj["id3"] != null && obj["id3"] != "" )
			{
				var temp:String = obj["id3"];
				if( vo.name == "所有商品"){
					temp += "temp";
				}
				vo.id3 =parasId(vo.subapp,temp,level);
				vo.currentId = vo.id3;
			}
			if( obj.hasOwnProperty("id") && obj["id"] != null && obj["id"] != "" )
			{
				vo.currentId = obj["id"];
			}
			if( obj.hasOwnProperty("namenaviURL") )
			{
				vo.namenaviURL = obj["namenaviURL"];
			}
			if( obj.hasOwnProperty("type") )
			{
				vo.type = obj["type"];
			}
			if( obj.hasOwnProperty("rowcount") )
			{
				vo.rowcount = obj["rowcount"];
			}
			if( obj.hasOwnProperty("imgURL") )
			{
				vo.imgURL = obj["imgURL"];
			}
			if( obj.hasOwnProperty("imgnaviURL") )
			{
				vo.imgnaviURL = obj["imgnaviURL"];
			}
			
			//
			var list:Array = [];
			if( obj.hasOwnProperty("nextNavList") && obj["nextNavList"] != null )
			{
				var tempList:Array = obj["nextNavList"] as Array;
				var len:int = tempList.length;
				level++;
				for( var i:int = 0 ; i < len ; i++ ){
					list.push( getNav( tempList[i]  , level , i , navType ) );
				}
				vo.nextNavList = list;
			}
			if( vo.nextNavList && vo.rowcount > vo.nextNavList.length ){
				vo.rowcount = vo.nextNavList.length;
			}
			
			MainModelLocator.getInstance().navDict[vo.currentId] = vo;
			MainModelLocator.getInstance().navSubappDict[ConditionVO.parasModule(vo.subapp)] = vo;
			return vo;
		}
		
		private static var  num:int = 100;
		public static function getNo():int
		{
			num ++;
			return num;
		}
	}
}